<!---
Copyright: (c) 2006 The MachBlog Authors
Authors: Matt Woodward (mpwoodward@gmail.com) & Peter J. Farrell (pjf@maestropublishing.com)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. 
You may obtain a copy of the License at 

http://www.apache.org/licenses/LICENSE-2.0 

Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
See the License for the specific language governing permissions and 
limitations under the License.

$Id: BlogListener.cfc 1187 2007-07-07 02:40:10Z pfarrell $

Notes:
This listener is autowired by ColdSpring.
--->
<cfcomponent displayname="BlogListener" output="false" extends="MachII.framework.Listener" hint="BlogListener for MachBlog">
	<cffunction name="configure" access="public" output="false" returntype="void">
		<!--- don't need to do anything here for now --->
	</cffunction>
	
	<cffunction name="setBlogService" access="public" output="false" returntype="void" hint="dependency: injected">
		<cfargument name="blogService" type="machblog.org.machblog.blog.BlogService" required="true" />
		<cfset variables.blogService = arguments.blogService />
	</cffunction>
	<cffunction name="getBlogService" access="public" output="false" returntype="machblog.org.machblog.blog.BlogService">
		<cfreturn variables.blogService />
	</cffunction>
	
	<cffunction name="setNotificationService" access="public" output="false" returntype="void" 
			hint="dependency: injected">
		<cfargument name="notificationService" type="machblog.org.machblog.notification.NotificationService" 
				required="true" />
		<cfset variables.notificationService = arguments.notificationService />
	</cffunction>
	<cffunction name="getNotificationService" access="public" output="false" 
			returntype="machblog.org.machblog.notification.NotificationService">
		<cfreturn variables.notificationService />
	</cffunction>
	
	<cffunction name="getDaysBlogging" access="public" output="false" returntype="numeric" 
			hint="Returns the total number of days since the first blog post.">
		<cfreturn getBlogService().getDaysBlogging() />
	</cffunction>
	
	<cffunction name="getCurrentUserDaysBlogging" access="public" output="false" returntype="numeric" 
			hint="Returns the number of days the currently logged-in user has been blogging">
		<cfreturn getBlogService().getCurrentUserDaysBlogging() />
	</cffunction>
	
	<cffunction name="processContactForm" access="public" output="false" returntype="void" 
			hint="Processes the contact form and announces the next event">
		<cfargument name="event" type="MachII.framework.Event" required="true" />
		
		<cfif getProperty("useCaptcha") AND arguments.event.isArgDefined("captchaMessage")>
				<cfset arguments.event.setArg('message',
						getProperty("resourceBundleService").getResourceBundle().getResource("captchafail")) />
		<cfelse>
			<cfset getNotificationService().emailContactForm(arguments.event.getArg("name"), 
																arguments.event.getArg("email"), 
																arguments.event.getArg("comments"), 
																getProperty("resourceBundleService").getResourceBundle().getResource("contactformemailsubject") 
																& " " & getProperty("resourceBundleService").getResourceBundle().getResource("from") 
																& " " & getProperty("blogHeaderTitle"), 
																getProperty("emailAuthor")) />
			
			<cfset arguments.event.setArg("message", 
					getProperty("resourceBundleService").getResourceBundle().getResource("contactformsuccessmessage")) />
		</cfif>
		
		<cfset announceEvent("showContactForm", arguments.event.getArgs()) />
	</cffunction>
</cfcomponent>